package com.liang.poi.controller;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.liang.poi.entity.People;
import com.liang.poi.entity.Student;

import java.io.IOException;
import java.util.*;

public class poiPrint1 {
    public static void main(String[] args) throws IOException {
        //模板地址
        String templateFilePath = "d:/data/template/";
        //生成文件的保存地址
        String destFilePath = "d:/data/template/word";
        Map<String, Object> datas = new HashMap<String, Object>();

        Student student1 = new Student();
        student1.setAge("12");
        student1.setIndex("1");
//        student1.setName("张三");
        student1.setSex("男");
        Student student2 = new Student();
        student2.setAge("122");
        student2.setIndex("11");
//        student2.setName("张三1");
        student2.setSex("男1");
        List<Student> studentList = new ArrayList<>();
        studentList.add(student1);
        studentList.add(student2);
        datas.put("lists",studentList);

        // 插件列表,可以去官网查看，有列循环，还有行循环，这里是行循环实例
        LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();

        //这里可以指定一个config类，用来指定一些规则，也可以改变模板中{{}}的这种格式
        Configure config = Configure.builder()
                .bind("lists", policy).build();

        XWPFTemplate compile = XWPFTemplate.compile(templateFilePath + "test03.docx",config);
        compile.render(datas);
        compile.writeToFile(destFilePath+"out_test3.docx");
        System.out.println("！！！！！！成功打印模板到"+destFilePath);
    }
}
